self.importScripts('https://cdn.jsdelivr.net/npm/spark-md5@3.0.2/spark-md5.min.js');

self.onmessage = async (e) => {
  const { chunks } = e.data;
  const spark = new self.SparkMD5.ArrayBuffer();
  
  for (let i = 0; i < chunks.length; i++) {
    const chunk = await chunks[i].arrayBuffer();
    spark.append(chunk);
    // 计算进度
    self.postMessage({
      progress: Math.round(((i + 1) / chunks.length) * 100)
    });
  }
  
  const hash = spark.end();
  self.postMessage({
    hash,
    progress: 100
  });
  self.close();
};
